

let _product = {



    getCategory : function (categoryId) {

        $.ajax({
            type    :   'GET',
            url     :    _common_util.getServerURL('category/get_all_category?categoryId=')+categoryId,
            success : function (res) {
                console.log(res);

                $.each(res.data,function (i,item) {
                    let categorystr = '<option value="'+item.categoryId+'">'+item.categoryName+'</option>';
                    $('#category-select').append(categorystr);
                })

            }
        })
    },
    
    
    addProduct :function () {

        let imgsrc =  $('#product-imgfile')[0].files[0].name ;
        let categoryId =  $('#category-select  option').filter(':selected').val();

        let itemName = $('#product-name').val();

        let price  =$('#product-price').val();
        let stock = $('#product-stock').val();
        let description  = $('#product-descript').val();

        let address  =$('#product-address').val();
        console.log(categoryId);
        console.log(imgsrc);

        $.ajax({
            type:'POST',
            url : _common_util.getServerURL('commodity/release_item'),
            dataType: 'json',
            data    :   {
                'categoryId' : categoryId,
                'source ' : 1 ,
                'itemName' : itemName,
                'stock' : stock,
                'price' : price,
                'address' : address,
                'description' : description,
                'image': imgsrc
            },
            success:function (res) {
                console.log(res);

                if (res.status === 0 ){
                    window.wxc.xcConfirm('发布成功，请继续购物吧');
                }
            }
        })
    }
}

